//
//  QCNavViewController.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/1/16.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit

class QCNavViewController: UINavigationController,UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
      
    }
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        return childViewControllers.count != 1
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            var title = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? ""
                viewController.hidesBottomBarWhenPushed = true
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: title, target: self, action: #selector(leftClick))
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func leftClick() {
        
        _ = popViewController(animated: true)
    }
   

}
